package models

import (
	"animal_srv/basic/appConfig"
	"context"
	"fmt"
)

// 虚拟库存
func SyncStock(goodsId, num int) {
	key := fmt.Sprintf("goods_stock_%d", goodsId)
	for i := 0; i < num; i++ {
		appConfig.Rdb.RPush(context.Background(), key, goodsId)
	}
}

// 获取寻库存数量
func GetStockLen(goodsId int) int64 {
	key := fmt.Sprintf("goods_stock_%d", goodsId)
	return appConfig.Rdb.LLen(context.Background(), key).Val()
}
